import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2024-10-29
 * Time: 8:31
 */
public class Test {
    public static Map<String, Integer> countWors(String[] words){
        Map<String, Integer> map = new HashMap<>();
        for(String s :words){
            if(map.get(s) == null){
                map.put(s, 1);
            }else{
                int val = map.get(s);
                map.put(s, val+1);
            }
        }
        return map;
    }

    public static void main(String[] args) {

        String[] words = {"hello", "abc", "hello", "this", "this", "this"};
        Map<String, Integer> map =  countWors(words);
        //System.out.println(map);
        Set<Map.Entry<String, Integer>> entrySet =  map.entrySet();
        for (Map.Entry<String, Integer>entry : entrySet){
            System.out.println("key："+entry + " val：" + entry.getValue());
        }
    }


}
